package zdream.pmfield.data.foe;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Zdream
 * @date 2023-11-09
 * @since 0.0.1
 */
public class MoveTemplate {
	public final int id;
	public String name;
	public int level;
	public Type.TypeWithWeight[] types;
	public MoveType attackerUsing, defenseUsing;
	public MoveTarget target;
	public String[] additions;

	/**
	 * 需要进行的检定属性
	 */
	public VStat[] vStats;

	public MoveCheckPair[] pairs;
	public int checkRateFixed;
	/**
	 * @see zdream.pmfield.stage.object.FoeActor#actionPoint
	 * @see zdream.pmfield.stage.object.FoeActor#movePoint
	 * @see #COST_ALL
	 */
	public byte actionPoint, movePoint;
	/**
	 * 行动点或移动点全都使用完. 名称叫 "跳过回合" 就是这样的技能
	 */
	public static final byte COST_ALL = -1;
	public String[] tags;
	public SubMove[] subs;

	public MoveTemplate(int id) {
		this.id = id;
	}

	public Type mainType() {
		for (Type.TypeWithWeight type : types) {
			if (type.weight >= Type.TypeWithWeight.WEIGHT_HIGH) {
				return type.type;
			}
		}
		throw new IllegalStateException("Fail to get main type of move: " + this);
	}

	public boolean hasTags(String tag) {
		return tags == null ? false : Arrays.stream(tags).anyMatch(tag::equals);
	}

	public static final String SUB_TITLE_CHARGING = "charging";
	public static final String SUB_TITLE_RELEASE = "release";

	public SubMove findSubMove(String title) {
		return subs == null ?
				null :
				Arrays.stream(subs).filter(sub -> title.equals(sub.title)).findAny().orElse(null);
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder(32);
		builder.append('#').append(id).append(' ').append(name).append(' ').append("Lv.").append(level);
		return builder.toString();
	}

	public static class SubMove {
		public final String title;
		public String[] additions;
		public VStat[] vStats;
		public MoveCheckPair[] pairs;
		public int checkRateFixed;

		public SubMove(String title) {
			this.title = Objects.requireNonNull(title);
		}
	}
}
